package com.firstsource.networking.ip.tracker.data.entities;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Parameter;
import com.firstsource.networking.ip.tracker.util.IPManipulator;

@Entity
@Table(name="interfaces")
public class Interface implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Id
	@Column
	@GeneratedValue(generator="InterfaceIndexSequence")
	@GenericGenerator(
				name="InterfaceIndexSequence",
				strategy="seqhilo",
				parameters={
						@Parameter(name="max_lo",value="1"),
						@Parameter(name="sequence",value="interface_idx_seq")
						
				}
			)
	private int idx = 0 ;

	@Column(name="ip_address")
	private long ipAddress = 0 ;

	@Column(name="mac")
	private String macAddr = null ;

	@Column(name="description")
	private String description = null ;

	@Column(name="name")
	private String name = null ;

	@Column(name="vlan")
	private int vlan = 0 ;

	@ManyToOne
	@JoinColumn(name="host_id")
	private Host host = null ;

	/**
	 * @return the idx
	 */
	public int getIdx() {
		return idx;
	}

	/**
	 * @param idx the idx to set
	 */
	public void setIdx(int idx) {
		this.idx = idx;
	}

	/**
	 * @return the ipAddress
	 */
	public String getIpAddress() {
		return IPManipulator.long2IP(ipAddress) ;
	}

	/**
	 * @param ipAddress the ipAddress to set
	 */
	public void setIpAddress(String addr) {
		this.ipAddress = IPManipulator.ip2Long(addr) ;
	}

	/**
	 * @return the macAddr
	 */
	public String getMacAddr() {
		return macAddr;
	}

	/**
	 * @param macAddr the macAddr to set
	 */
	public void setMacAddr(String macAddr) {
		this.macAddr = macAddr;
	}

	/**
	 * @return the description
	 */
	public String getDescription() {
		return description;
	}

	/**
	 * @param description the description to set
	 */
	public void setDescription(String description) {
		this.description = description;
	}

	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @return the vlan
	 */
	public int getVlan() {
		return vlan;
	}

	/**
	 * @param vlan the vlan to set
	 */
	public void setVlan(int vlan) {
		this.vlan = vlan;
	}

	public void setHost(Host host) {
		this.host = host;
	}

	public Host getHost() {
		return host;
	}

	
}
